/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controllers;

import controllers.mysqlconnector.ConexionBD;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import models.Sala;


/**
 *
 * @author Erik Zubia
 */
public class Salas extends ConexionBD {
    
    DefaultTableModel dtmCine;
    List<Sala> salas = new ArrayList<>();
    static Sala sala = new Sala();
    
    public void agregarSala(Integer numSala, String filas, 
                    String columnas, String tipoSala){
     consulta = "insert into salas(idSalas, "
             + "tipoSala, filas, columnas) "
             + "values ("+numSala+", '"+tipoSala+"', "
             + "'"+filas+"', '"+columnas+"');";
     
        realizarActualizacion(consulta);
    }
    public ResultSet listarSalas(){
        consulta = "select idSalas from salas;";
        regreso = realizarConsulta(consulta);
        return regreso;
    }
    public void eliminarSala(String sala){
     consulta = "delete from salas where idSalas="+sala+";";
     
        realizarActualizacion(consulta);
     JOptionPane.showMessageDialog(null, "Sala eliminada con exito");
    }
    
    
   public DefaultTableModel getSalas(){
       
    String [] titulos = {"Numero Sala","Tipo de Sala","Filas","Columnas"};
    String [] registros = new String [4];
    consulta = "select * from salas;";
    ResultSet rs = super.realizarConsulta(consulta);
    if(rs != null){
        try {
            dtmCine = new DefaultTableModel(null,titulos);
            rs.next();
            registros [0] = rs.getString("idSalas");
            registros [1] = rs.getString("tipoSala");
            registros [2] = rs.getString("filas");
            registros [3] = rs.getString("columnas");
            dtmCine.addRow(registros);
            while(rs.next()){
                registros [0] = rs.getString("idSalas");
                registros [1] = rs.getString("tipoSala");
                registros [2] = rs.getString("filas");
                registros [3] = rs.getString("columnas");
                
                dtmCine.addRow(registros);
            }
        } catch (SQLException ex) {
            Logger.getLogger(Salas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }      
    return dtmCine;
} 
    
    
}

